| Conditions | 2 |
| Paths | 2 |
| Total Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* global API */ |
||
| 36 | .controller('SettingsCtrl', ['$scope', 'notify', '$routeParams', function ($scope, notify, $routeParams) { |
||
| 37 | $scope.settings = { |
||
| 38 | accounts: [], |
||
| 39 | ignoreProtocol: true, |
||
| 40 | ignoreSubdomain: true, |
||
| 41 | ignorePort: true, |
||
| 42 | ignorePath: true, |
||
| 43 | generatedPasswordLength: 12, |
||
| 44 | remember_password: true, |
||
| 45 | refreshTime: 60, |
||
| 46 | disable_browser_autofill: true, |
||
| 47 | debug: false |
||
| 48 | }; |
||
| 49 | $scope.errors = []; |
||
| 50 | |||
| 51 | $scope.tabActive = ($routeParams.tab) ? parseInt($routeParams.tab) : 1; |
||
| 52 | |||
| 53 | API.runtime.sendMessage(API.runtime.id, {'method': 'getRuntimeSettings'}).then(function (settings) { |
||
| 54 | $scope.errors = []; |
||
| 55 | if (settings) { |
||
| 56 | $scope.settings = angular.copy(settings); |
||
| 57 | } |
||
| 58 | $scope.$apply(); |
||
| 59 | }); |
||
| 60 | |||
| 61 | $scope.saving = false; |
||
| 62 | $scope.saveSettings = function (redirect) { |
||
| 63 | $scope.errors = []; |
||
| 64 | var settings = angular.copy($scope.settings); |
||
| 65 | $scope.saving = true; |
||
| 66 | API.runtime.sendMessage(API.runtime.id, {method: "saveSettings", args: settings}).then(function () { |
||
| 67 | setTimeout(function () { |
||
| 68 | if(redirect) { |
||
| 69 | window.location = '#!/'; |
||
| 70 | } |
||
| 71 | $scope.saving = false; |
||
| 72 | }, 750); |
||
| 73 | }); |
||
| 74 | }; |
||
| 75 | |||
| 76 | $scope.removeSite = function (site) { |
||
| 77 | var idx = $scope.settings.ignored_sites.indexOf(site); |
||
| 78 | $scope.settings.ignored_sites.splice(idx, 1); |
||
| 79 | }; |
||
| 80 | |||
| 81 | $scope.ignoreSite = ''; |
||
| 82 | $scope.addSite = function (site) { |
||
| 83 | $scope.settings.ignored_sites.push(site); |
||
| 84 | $scope.ignoreSite = ''; |
||
| 85 | }; |
||
| 86 | |||
| 87 | $scope.removeAccount = function (account) { |
||
| 88 | var idx = $scope.settings.accounts.indexOf(account); |
||
| 89 | $scope.settings.accounts.splice(idx, 1); |
||
| 90 | $scope.saveSettings(false); |
||
| 91 | }; |
||
| 92 | |||
| 93 | $scope.cancel = function () { |
||
| 94 | window.location = '#!/'; |
||
| 95 | }; |
||
| 96 | $scope.addAccount = function () { |
||
| 97 | window.location = '#!/accounts/add'; |
||
| 98 | }; |
||
| 99 | }]); |
||
| 100 | }()); |
||
| 102 |